<template>
	<view class="buss-detail">
		<k-navbar title="商圈详情"></k-navbar>
		<view class="top-panle">
			<view class="u-flex shop-box">
				<u-image :src="shop.merchantImage" style="width:163rpx;height:143rpx;border-radius: 10rpx;" mode=""></u-image>
				<view class="u-flex-1 content">
					<view class="shop-title u-line-1">
						{{shop.merchantShortName}}
					</view>
					<view class="u-flex u-row-right">
						<!-- <view class="u-flex rate">
							<u-rate :count="5" v-model="value" size="24" active-color="#FFA400"></u-rate>
							<text>5分</text>
						</view>
						 -->
						<u-icon style="padding-right: 50rpx;" size="40" name="map-fill" color="#FF6600" @click="mapShow = true"></u-icon>
					</view>
					<view class="u-flex u-row-between">
						<view class="status">
							正常营业
						</view>
						<view class="">
							<u-button v-if="isFocus == 0" type="warning" shape="circle" size="mini" @click="fav">退出商圈</u-button>
							<u-button v-if="isFocus == 1" type="warning" shape="circle" size="mini" @click="fav">加入商圈</u-button>
						</view>
					</view>
				</view>
			</view>
			<!-- 描述 -->
			<view v-show="!showDes" class="shop-des u-flex" @click="showDes = true">
				<view class="u-line-1 u-flex-1">
				简介：{{shop.merchantSynopsis}}
				</view>
				<u-icon name="arrow-down" size="26" color="#636363"></u-icon>
			</view>
			<view v-show="showDes" class="shop-des">
				<view class="">
				简介：{{shop.merchantSynopsis}}
				</view>
				<view style="text-align: center;" @click="showDes = false">
					<u-icon name="arrow-up" size="26" color="#636363"></u-icon>
				</view>
			</view>
			<!-- 描述 end -->
		</view>
		<view class="content-panle">
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change" :is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<goodList v-if="productList.length > 0" :tabbar="productList"></goodList>
					<view v-else class="empty">
						<image src="../../static/businessDistrict/empty.png" mode=""></image>
						<view class="">暂无商品</view>
						<view class="">商家正在火速添加</view>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<!-- 活动 -->
					<view class="active-item" v-for="(item, index) in activeList" :key="index">
						<!-- <view class="time">{{item.expireDate}}</view> -->
						<view class="panle">
							<image src="../../static/businessDistrict/redpackage.png" style="width: 690rpx;height:240rpx;" mode=""></image>
							<view class="info u-flex u-row-between">
								<view class="">红包数量{{item.redEnvelopesNum}}</view><!-- 已参加人数：208 -->
								<view class="text-btn" @click="redPackage(item)">查看详情</view>
							</view>
						</view>
					</view>
					<view v-if="activeList.length == 0" class="empty">
						<image src="../../static/businessDistrict/empty.png" mode=""></image>
						<view class="">暂无数据</view>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<!-- 商户 -->
					<view class="u-flex shop-item">
						<view class="adress u-flex u-flex-8"@click="openMap">
							<u-icon style="padding-right: 10rpx;" name="map" size="40" color="##BFBFBF"></u-icon>
							<view class="">{{shop.merchantAddress}}</view>
						</view>
						<view class="u-flex-3" style="text-align: center;" @click="openPhone">
							<u-icon name="phone" color="#FF6600" size="40"></u-icon>
						</view>
					</view>
					<view class="u-flex shop-item-instruct">
						<view class="name">门店营业时间</view>
						<view class="">{{shop.businessTimeDesc}}</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- <view class="bottom-action">
			<view class="detail-left" @click="showPopup = !showPopup">
				共1件，实际付款
				<text class="price">￥9.8</text>
				<u-icon class="icon" name="arrow-down" size="30" color="#999999"></u-icon>
			</view>
			<u-button class="buy-btn" type="primary" color="#fffff" @click="settlement">去结算</u-button>
		</view> -->
		<u-popup 
			v-model="showPopup"
			mode="bottom"
			z-index="100"
			border-radius="20"
			:mask-close-able="false"
			>
			<view class="order-detail">
				<view class="header">
					费用明细
					<u-icon name="close-circle" color="#888888" size="40" @click="closePopup"></u-icon>
				</view>
				<view class="u-flex detail-box">
					<image src="../../static/agricultureProduct/banner1.png" style="width:140rpx;height: 140rpx;border-radius: 15rpx;" mode=""></image>
					<view class="u-flex-1 content">
						<view class="title">
							兵王
						</view>
						<view class="des">
								月售234
						</view>
						<view class="u-flex u-row-between">
							<view class="price">
								￥9.8
							</view>
							<view class="">
								X1
							</view>
						</view>
					</view>
				</view>
				<view class="sweet u-flex u-row-between">
					<view class="">糖果抵用</view>
					<view class="primary">-￥2.4</view>
				</view>
			</view>
		</u-popup>
		<open-third-map :show="mapShow" :latitude="shop.latitude" :longitude="shop.longitude" :name="shop.merchantAddress" @success="mapShow = false"></open-third-map>
	</view>
</template>

<script>
	import kNavbar from '@/components/navbar/index'
	import goodList from './mallMenu.vue'
	import openThirdMap from '@/components/map/openThirdMap.vue'
	export default {
		components: {
			goodList,
			kNavbar,
			openThirdMap
		},
		data() {
			return {
				mapShow: false,
				id: '', // 商户id
				productList: [], // 商品列表
				showPopup: false,
				showDes: false,
				value: 5,
				list: [
					{
						name: '点餐'
					},
					{
						name: '活动'
					},
					{
						name: '商家'
					},
				],
				current: 0,
				swiperCurrent: 0,
				shop: {},
				isFocus: 1,
				activeList: [],
			}
		},
		
		onLoad(option) {
			this.shop = JSON.parse(option.shop)
			this.id = this.shop.merchantId;
			let token = uni.getStorageSync('token') || ''
			if (token) {
				this.getShop()
				this.getActive()
			} 
			this.getData()
		},
		methods:{
			getActive() {
				this.$u.api.activityList({
					businessId : this.id,
					state: 0,
					type: 2
				}).then(res => {
					if (res.code == 0) {
						this.activeList = res.data;
					} else {
						uni.showToast({
							icon:'none',
						    title: res.msg
						});
					}
				})
			},
			fav() {
				if (uni.getStorageSync('token')) {
					let apiName = '';
					if (this.isFocus == 0) {
						apiName = 'putMerchantFocus'
					} else {
						apiName = 'postMerchantFocus'
					}
					this.$u.api[apiName]({
						mid: this.id,
						type: 2
					}).then(res => {
						if (res.code == 0) {
							uni.showToast({
								icon:'none',
							    title: '操作成功'
							});
							this.isFocus = this.isFocus == 0? 1: 0
						} else {
							uni.showToast({
								icon:'none',
							    title: res.msg
							});
						}
					})
				} else {
					this.$u.route('/pages/login/index');
				}
			},
			getShop() {
				this.$u.api.merchantFocusDetail({
					mid: this.id,
					latitude: this.shop.latitude,
					longitude: this.shop.longitude,
					type: 2
				}).then(res => {
					if (res.code == 0) {
						this.isFocus = res.data.isFocus; //0已关注 1未关注
					} else {
						uni.showToast({
							icon:'none',
						    title: res.msg
						});
					}
				})
			},
			openPhone() {
				uni.makePhoneCall({
				    phoneNumber:  this.shop.merchantTel//仅为示例
				});
			},
			// tab栏切换
			change(index) {
				if (index == 1) {
					if (!uni.getStorageSync('token')) {
						uni.navigateTo({
							url:'/pages/login/index'
						})
					}
				}
				this.swiperCurrent = index;
				
			},
			transition({ detail: { dx } }) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({ detail: { current } }) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			closePopup() {
				this.showPopup = false;
			},
			// 查看红包
			redPackage(item) {
				let params = {
					businessId: this.id,
					id: item.id,
					latitude: this.shop.latitude,
					longitude: this.shop.longitude,
				}
				uni.navigateTo({
					url: '/pages/businessDistrict/redPackageDetail'+ '?detail=' + JSON.stringify(params)
				})
			},
			settlement() {
				uni.navigateTo({
					url: '/pages/businessDistrict/createOffinelineOrder'
				})
			},
			getData () {
				let apiName = '';
				let token = uni.getStorageSync('token') || ''
				console.log('token', token)
				if (token) {
					apiName = 'offlineFoodList'
				} else {
					apiName = 'openOfflineFoodList'
				}
				this.$u.api[apiName]({
					mid: this.id
				}).then(res => {
					if (res.code == 0) {
						this.productList = res.data;
					} else {
						uni.showToast({
							icon:'none',
						    title: res.msg
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.buss-detail {
		width: 100%;
		height: 100%;
	}
	.content-panle {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}
	.swiper-box {
		flex: 1;
	}
	.swiper-item {
		height: 100%;
	}
	.top-panle {
		padding: 30rpx;
		.shop-des {
			margin-top: 20rpx;
			color: #636363;
			font-size: 24rpx;
		}
	}
	.shop-item {
		padding-left: 40rpx;
		height: 66rpx;
		.adress {
			padding-right: 10rpx;
			&::after {
				content: '';
				display: block;
				width: 2rpx;
				height: 40rpx;
				background-color: #DAD9D9;
			}
		}
	}
	.shop-item-instruct {
		padding: 30rpx;
		font-weight: bold;
		font-size: 30rpx;
		color: #000;
		line-height: 70rpx;
		.name {
			padding-right: 20rpx;
		}
	}
	.shop-box {
		
		.content {
			margin-left: 26rpx;
			font-size: 30rpx;
		}
		.shop-title {
			min-width: 0;
		}
		.rate {
			margin-top: 10rpx;
			font-size: 24rpx;
			color: #636363;
		}
		.status {
			color: #FF6600;
			font-size: 24rpx;
		}
	}
	.bottom-action {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 101;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		display: flex;
		background-color: #fff;
		.price {
			color: #FF6600;
			font-size: 36rpx;
		}
		.icon {
			padding-left: 30rpx;
		}
		.detail-left {
			text-align: center;
			width: 66%;
			color: #606163;
			font-size: 24rpx;
		}
		.buy-btn {
			margin-right: 0;
			border-radius: 0;
			font-size: 30rpx;
			color: #fff;
			width: 34%;
			background: linear-gradient(90deg, #FF6600, #FF9933);
			border: 0;
		}
		
	}
	/deep/.u-default-hover {
		color: #fff;
	}
	.order-detail {
		padding-bottom: 100rpx;
		.header {
			position: relative;
			line-height: 100rpx;
			color: #000000;
			font-size: 36rpx;
			text-align: center;
			border-bottom: 1rpx solid #BCBBBB;
			
			/deep/.uicon-close-circle {
				position: absolute;
				right: 30rpx;
				top: 0;
				line-height: 100rpx;
			}
		}
		.primary {
			color: #FF6600;
		}
		.sweet {
			padding: 0 30rpx;
			font-size: 28rpx;
			color: #333;
		}
	}
	.detail-box {
		padding: 30rpx 30rpx;
		margin-bottom: 30rpx;
		.content {
			margin-left: 20rpx;
		}
		.price {
			color: #FF6600;
			font-size: 30rpx;
		}
		.des {
			margin-top: 8rpx;
			color: #999999;
			font-size: 24rpx;
		}
	}
	
	.active-item {
		width: 690rpx;
		margin: 30rpx auto;
		.time {
			text-align: center;
			font-size: 24rpx;
			color: #231815;
		}
		.panle {
			margin-top: 16rpx;
			color: #585858;
			font-size: 24rpx;
			border-radius: 10rpx;
			overflow: hidden;
			box-shadow: 0rpx 0rpx 18rpx 0rpx rgba(0, 0, 0, 0.31);
			
			.info {
				padding: 20rpx 20rpx 25rpx 20rpx;
			}
		}
		.text-btn {
			color: #FF6600;
			cursor: pointer;
		}
	}
	.empty {
		margin-top: 50rpx;
		text-align: center;
		color: #FF6600;
		font-size: 30rpx;
		line-height: 50rpx;
		image {
			width: 128rpx;
			height: 121rpx;
		}
	}
	
</style>
